package asteroids.expressions;

import java.util.*;

import asteroids.types.*;

public abstract class MathBinaryExpression extends BinaryExpression {

	protected MathBinaryExpression(int line, int column, Expression e1, Expression e2) {
		super(line, column, e1, e2);
	}
	
	@Override
	public List<String> getTypeCheckErrorsExpressions(List<String> typeErrors, Map<String, Type> globals) {
		if(getFirstExpression().evaluate(null, globals).getClass() != DoubleType.class) 
			typeErrors.add("Line: " + getLine() + " Column: " + getColumn() + " - The left operand, " + getFirstExpression().toString() + " is expected to be from the type 'double'.");
		if(getSecondExpression().evaluate(null, globals).getClass() != DoubleType.class) 
			typeErrors.add("Line: " + getLine() + " Column: " + getColumn() + " - The right operand, " + getSecondExpression().toString() + " is expected to be from the type 'double'.");
		typeErrors = getFirstExpression().getTypeCheckErrorsExpressions(typeErrors, globals);
		typeErrors = getSecondExpression().getTypeCheckErrorsExpressions(typeErrors, globals);
		return typeErrors;
	}

}
